package com.mauroleon.base.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mauroleon.base.service.JpaBaseService;

@Service
public abstract class JpaBaseServiceImpl<T extends Object, ID extends Serializable>
		implements JpaBaseService<T, ID> {

	protected abstract JpaRepository<T, ID> getBaseDAO();

	@Transactional
	@Override
	public void deleteInBatch(Iterable<T> arg0) {
		getBaseDAO().deleteInBatch(arg0);
	}

	@Override
	public List<T> findAll() {
		return getBaseDAO().findAll();
	}

	@Override
	public List<T> findAll(Sort arg0) {
		return getBaseDAO().findAll(arg0);
	}

	@Override
	public void flush() {
		getBaseDAO().flush();
	}

	@Transactional
	@Override
	public List<T> save(Iterable<? extends T> arg0) {
		return getBaseDAO().save(arg0);
	}

	@Transactional
	@Override
	public T saveAndFlush(T arg0) {
		return getBaseDAO().saveAndFlush(arg0);
	}

	@Override
	public Page<T> findAll(Pageable pageable) {
		return getBaseDAO().findAll(pageable);
	}

	@Transactional
	@Override
	public T save(T entity) {
		return getBaseDAO().save(entity);
	}

	@Override
	public T findOne(ID id) {
		return getBaseDAO().findOne(id);
	}

	@Override
	public boolean exists(ID id) {
		return getBaseDAO().exists(id);
	}

	@Override
	public long count() {
		return getBaseDAO().count();
	}

	@Transactional
	@Override
	public void delete(ID id) {
		getBaseDAO().delete(id);
	}

	@Transactional
	@Override
	public void delete(T entity) {
		getBaseDAO().delete(entity);
	}

	@Transactional
	@Override
	public void delete(Iterable<? extends T> entities) {
		getBaseDAO().delete(entities);
	}

	@Transactional
	@Override
	public void deleteAll() {
		getBaseDAO().deleteAll();
	}

}
